import Vue from "vue";
import fastClick from "fastclick";
// vue ydui
import YDUI from "vue-ydui";
import "vue-ydui/dist/ydui.rem.css";

import VueLazyload from "vue-lazyload";
import router from "./router";
import store from "./store";
import utils from "./utils/utils";

import api from './api'
import devApi from './api/dev'

import "./assets/style/common.scss";
import "./components/global-components";
//import remJs from "./utils/rem";
import App from "./App.vue";


import loadErrorImg from "./assets/images/img-load-error.svg";
import bankGif from "./assets/images/blank.gif";

utils.init()

Vue.use(YDUI);

Vue.use(VueLazyload, {
  error: loadErrorImg,
  loading: bankGif,
});

Vue.use({
  install(vue) {
    vue.prototype.$eventBus = eventBus;
    if (process.env.NODE_ENV === 'production') {
      vue.prototype.$api = api;
    } else {
      vue.prototype.$api = devApi;
    }
  },
});

document.addEventListener(
  "DOMContentLoaded",
  function () {
    fastClick.attach(document.body);
  },
  false
);

const eventBus = new Vue({});

const app = new Vue({
  el: "#app",
  render: h => h(App),
  router,
  store,
});

router.beforeEach((to, from, next) => {
  //全局动画;
  const toDepth = to.path.split("/").length;
  const fromDepth = from.path.split("/").length;
  let transitionName = null;

  if (toDepth === fromDepth) {
    transitionName = null;
  } else {
    transitionName = toDepth < fromDepth ? "slide-right" : "slide-left";
  }

  app.$store.commit("SET_PAGE_TRANSITION_PROP", {
    transitionName
  });
  app.$nextTick(() => {
    next();
  });
});